/* $Id: ContestsModel.java 137 2011-08-29 20:33:36Z altdotua@gmail.com $ */

package alt.djudge.frontend.server.models;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.criterion.Order;

import alt.djudge.frontend.server.datatypes.ContestEntry;


public class ContestsModel
{
	final static ModelSettings<ContestEntry> settings = new ModelSettings<ContestEntry>()
	{
		@Override
		public Order getOrdering()
		{
			return Order.asc("sid");
		}
		
		@Override
		public Class<ContestEntry> getEntryClass()
		{
			return ContestEntry.class;
		}
	};
	
	private static CoreInterface<ContestEntry> core = new DBAbstractor<ContestEntry>(settings).getModel();
	
		
	public static List<ContestEntry> getAllEntries()
	{
		return core.getAllEntries();
	}

	public static List<ContestEntry> getEntries(Map<String, Object> map)
	{
		return core.getEntries(map);
	}

	public static ContestEntry getEntry(Long contestId)
	{
		return core.getEntry(contestId);
	}
	
	public static boolean deleteEntry(Long contestId)
	{
		return core.deleteEntry(contestId);
	}
	
	public static CoreInterface<ContestEntry> getCore()
	{
		return core.getAdapter();
	}

	public static Map<Long, ContestEntry> getEntriesMap()
	{
		List<ContestEntry> list = getAllEntries();
		HashMap<Long, ContestEntry> result = new HashMap<Long, ContestEntry>();
		for (ContestEntry entry: list)
			result.put(entry.getId(), entry);
		return result;
	}

	public static List<ContestEntry> getActiveContests(int page)
	{
		Map<String, Object> filter = new HashMap<String, Object>();
		//filter.put("active", true);
		return core.getEntries(filter);
	}
}
